/**
 * 绘制环状围墙
 * @param {Earth} options.earth 渲染容器
 * @param {Array} options.position 圆环中心位置 [ lng, lat ]
 * @param {Array} options.color 圆环颜色 colorArray
 * @param {Number} options.scale 圆环缩放等级 笛卡尔坐标 [ x, y, z ]
 * 
 * 
 * @returns {DrawCircleWall} DrawCircleWall实例  XEObj属性XE实例  
 */

function DrawCircleWall (options) {
    let radian = Math.PI / 180;

    const fragmentShaderSource = `
        varying vec3 v_positionEC;
        varying vec3 v_normalEC;
        varying vec2 v_st;
        varying vec4 v_color;
        uniform sampler2D u_image;
        uniform vec4 u_color;
        void main()
        {
            float powerRatio = fract(czm_frameNumber / 30.0) + 1.0;
            float alpha = pow(1.0 - v_st.t, powerRatio);
            gl_FragColor = vec4(u_color.rgb, alpha*u_color.a);
        }
    `;
    const renderState = XE.Obj.CustomPrimitive.getRenderState(true, true);
    renderState.cull.enabled = false;
    const cylinder = XE.Obj.CustomPrimitive.Geometry.createCylinder(6.0, 6.0, 1.0, 12);
    const config = {
        position: [ options.position[0] * radian, options.position[1] * radian, 0 ],
        scale: options.scale || [10, 10, 100],
        positions: cylinder.positions,
        sts: cylinder.sts,
        indices: cylinder.indices,
        renderState,
        color: options.color || [1.0, 1.0, 0.0, 1.0],
        canvasWidth: 1.0,
        fragmentShaderSource,
        show: options.show === undefined ? true : options.show
    };

    let p = new XE.Obj.CustomPrimitive(options.earth);
    p.xbsjFromJSON(config);

    this.XEObj = p
    p._node = this
    this.changeStatus = options.changeStatus === undefined ? true : options.changeStatus
}

DrawCircleWall.prototype.destroy = function () {
    this.XEObj._node = null
    this.XEObj.destroy()
}

DrawCircleWall.prototype.update = function (options) {
    if (!this.changeStatus) {
        return
    }
    this.XEObj[k] = options[k]
}

DrawCircleWall.prototype.setShow = function (options) {
    this.XEObj.show = options
}


export default DrawCircleWall